package com.ubank.service;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

import com.ubank.utils.MockDialog;
import com.ubank.utils.PublicUtils;

public class ScreenOffService extends Service
{
	ScreenOffListener			screenOffReceiver;
	private final static String	SCREEN_OFF	= "android.intent.action.SCREEN_OFF";

	@Override
	public IBinder onBind(Intent intent)
	{
		return null;
	}

	@Override
	public void onCreate()
	{
		super.onCreate();
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId)
	{
		screenOffReceiver = new ScreenOffListener();
		IntentFilter filter = new IntentFilter(SCREEN_OFF);
		registerReceiver(screenOffReceiver, filter);
		return START_STICKY;
	}

	public class ScreenOffListener extends BroadcastReceiver
	{
		@Override
		public void onReceive(Context context, Intent intent)
		{
			if (intent.getAction().equals(SCREEN_OFF))
			{
				if (!MockDialog.isLock())
				{
					PublicUtils.lockScreen(ScreenOffService.this);
				}
			}
		}
	}
}
